#include "QD3DTransformUtils.h"

QD3DTransformUtils::QD3DTransformUtils() : QD3DUtils()
{

}

QD3DTransformUtils::QD3DTransformUtils (QD3DContext *pContext) : QD3DUtils (pContext)
{

}

QD3DTransformUtils::~QD3DTransformUtils()
{

}

void QD3DTransformUtils::loadIdentity ()
{
	int curMode = __p_context->curMode;
	__p_context->matrixConstVars.vals[curMode] = glm::mat4 ();
}

void QD3DTransformUtils::loadMatrix (glm::mat4 mat)
{
	int curMode = __p_context->curMode;
	__p_context->matrixConstVars.vals[curMode] = mat;
}

void QD3DTransformUtils::multiMatrix (glm::mat4 mat)
{
	int curMode = __p_context->curMode;
	__p_context->matrixConstVars.vals[curMode] *= mat;
}

void QD3DTransformUtils::pushMatrix ()
{
	int curMode = __p_context->curMode;
	__p_context->matStacks[curMode].push (
			__p_context->matrixConstVars.vals[curMode]);
}

void QD3DTransformUtils::popMatrix ()
{
	int curMode = __p_context->curMode;
	if (__p_context->matStacks[curMode].size ())
		__p_context->matrixConstVars.vals[curMode] =
				__p_context->matStacks[curMode].pop ();
}

void QD3DTransformUtils::setMatrixMode (int mode)
{
	__p_context->curMode = mode;
}

void QD3DTransformUtils::applyMatrix (int slot)
{
	QD3DContext::MatrixConstVars transposedMats;
	transposedMats.vals[0] = glm::transpose (__p_context->matrixConstVars.vals[0]);
	transposedMats.vals[1] = glm::transpose (__p_context->matrixConstVars.vals[1]);
	transposedMats.vals[2] = glm::transpose (__p_context->matrixConstVars.vals[2]);
	updateSubresource (__p_context->pMatrixDxConstBuf, 0, &transposedMats);
	QVector< ID3D11Buffer * > constDxBufPtrs (1);
	constDxBufPtrs[0] = __p_context->pMatrixDxConstBuf;
	setConstBufs (QD3DUtils::VERTEX_SHADER, slot, constDxBufPtrs);
	setConstBufs (QD3DUtils::PIXEL_SHADER, slot, constDxBufPtrs);
}
